<template>
	<view>
		<view class="submit" @click="gopay"><text>支付</text></view>
	</view>
</template>
<style lang="scss">
	.submit{
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		margin: 32rpx;
		line-height: 88rpx;
		height: 80rpx;
		text-align: center;
		border-radius: 10rpx;
		background-color: #FFFFFF;
	}
</style>
<script>
	import pays from '@/utils/pay.js'
	export default {
		data() {
			return {
				userinfo:{}
			}
		},
		onShow(){
			// this.$u.api.getUserInfo().then(res => {
			// 	this.userinfo = res.data;
			// });
		},
		methods: {
			gopay(){
				
				if(!this.userinfo.thirdPartyUser){
					this.$u.api.login({
						provider:"weixin",
						success:LoginRes => {
							this.$u.toast(LoginRes.msg);
							if (LoginRes.code == 1) {
								// uni.setStorageSync('login', '1');
								// uni.setStorageSync('token', LoginRes.data.token);
								// uni.setStorageSync('user', LoginRes.data.user);
								this.userinfo = LoginRes.data.user;
								this.pay();
							}
						}
					})
				}else{
					this.pay();
				}
				
			},
			pay(){
				pays.pay({
					provider:"weixin",
					url:"plugin/wechat/imitatePay",
					data:{user_id:this.userinfo.id},
					success:payRes => {
						console.log(payRes);
						if(payRes.errMsg == "requestPayment:ok"){
							uni.navigateTo({
								url:"/pages/order/info?id="+orderRes.data.id
							})
						}
					},
					fail:payErr => {
						uni.navigateTo({
							url:"/pages/order/info?id="+orderRes.data.id
						})
					}
				},this);
			}
		}
	}
</script>

<style>

</style>
